package com.sise.wangzhan;

import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;

/**
 * @Classname MyInterceptor
 * @Description TODO    将原来的HttpRequest请求对象转换成自定义的MyHttpRequest.
 * @Date 2020/4/2 10:56
 * @Created by wangzhan
 */
public class MyInterceptor implements ClientHttpRequestInterceptor {
    @Override
    public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {

        System.out.println("这是自定义拦截器的实现===============");
        System.out.println("     原来的RUI："+httpRequest.getURI());

        //换成新的请求对象
        MyHttpRequest newRequest = new MyHttpRequest(httpRequest);
        System.out.println("     拦截后的URI："+ newRequest.getURI());

        return clientHttpRequestExecution.execute(newRequest,bytes);
    }
}
